
//
//  OneViewController.m
//  AYWrapTextView
//
//  Created by AY on 16/6/24.
//  Copyright © 2016年 Jasperay. All rights reserved.
//

#import "OneViewController.h"
#import "Masonry.h"

@interface OneViewController ()<AYAdaptiveTextViewDelegate>


@end

@implementation OneViewController

- (UIButton *)sendButton
{
    if (!_sendButton) {
        //发送按钮
        UIButton *sendBtn = [[UIButton alloc] init];
        _sendButton = sendBtn;
        sendBtn.backgroundColor = [UIColor colorWithRed:183/255.0 green:93/255.0 blue:144/255.0 alpha:1];
        [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
        sendBtn.layer.cornerRadius = 5;
    }
    return _sendButton;
}

- (UIView *)toolBar
{
    if (!_toolBar) {
        _toolBar = [[UIView alloc] init];
        _toolBar.backgroundColor = [UIColor grayColor];
    }
    return _toolBar;
}

- (AYAdaptiveTextView *)adapTextView
{
    if (!_adapTextView) {
        _adapTextView = [[AYAdaptiveTextView alloc] init];
        _adapTextView.font = [UIFont systemFontOfSize:16];
        _adapTextView.placeholder = @"输入文字测试...";
        _adapTextView.delegate = self;
        /** 是否可以伸缩 */
        _adapTextView.isCanExtend = YES;
        /** 伸缩行数 */
        _adapTextView.extendLimitRow = 4;
        _adapTextView.layer.borderWidth = 1;
        _adapTextView.layer.borderColor = [UIColor colorWithRed:122/255.0 green:122/255.0 blue:122/255.0 alpha:1].CGColor;
        _adapTextView.layer.cornerRadius = 3;

    }
    return _adapTextView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor orangeColor];
    
    [self.view addSubview:self.toolBar];

    [self.toolBar addSubview:self.sendButton];

    [self.toolBar addSubview:self.adapTextView];

}

- (void)AYAdaptiveTextView:(AYAdaptiveTextView *)AYAdaptiveTextView textDidChanged:(NSString *)text
{
    NSLog(@"编辑文字过程中..");
}
- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    
    [_toolBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom).offset(-400);
        make.height.mas_equalTo(@44).priorityLow();
    }];
    
    [_sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.toolBar.mas_right).offset(-5);
        make.bottom.equalTo(self.toolBar.mas_bottom).offset(-7);
        make.height.mas_equalTo(@30);
        make.width.mas_equalTo(@50);
    }];

    
    [_adapTextView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.toolBar.mas_left).offset(5);
        make.right.equalTo(self.sendButton.mas_left).offset(-10);
        make.bottom.equalTo(self.toolBar.mas_bottom).offset(-5);
        make.top.equalTo(self.toolBar.mas_top).offset(5);
    }];

 
}

@end
